#include <iostream>
#include <string>

using namespace std;

// 声明一个结构体类型 Books
struct Books
{
    string title;
    string author;
    string subject;
    int book_id;

    Books(){}

    // 构造函数
    Books(string t, string a, string s, int id)
        : title(t), author(a), subject(s), book_id(id) {}
};

void printBook(struct Books book)
{
    cout << "书标题 : " << book.title << endl;
    cout << "书作者 : " << book.author << endl;
    cout << "书类目 : " << book.subject << endl;
    cout << "书 ID : " << book.book_id << endl;
    cout << "========================="<< endl;
}

// 打印书籍信息的函数，接受一个指向 Books 结构体的指针
void printBookInfo(const Books* book) {
    cout << "书籍标题: " << book->title << endl;
    cout << "书籍作者: " << book->author << endl;
    cout << "书籍类目: " << book->subject << endl;
    cout << "书籍 ID: " << book->book_id << endl;
    cout << "===========*==============" << endl;
}

int main()
{
    Books book1; // 定义结构体类型 Books 的变量 book1
    Books book2("CSS 教程", "Runoob", "前端技术", 12346); // 定义结构体类型 Books 的变量 book2

    // book1 详述
    book1.title = "C++ 教程";
    book1.author = "Runoob";
    book1.subject = "编程语言";
    book1.book_id = 12345;

    // book2 详述
    // book2.title = "CSS 教程";
    // book2.author = "Runoob";
    // book2.subject = "前端技术";
    // book2.book_id = 12346;

    // 输出 book1 信息
    //    cout << "第一本书标题 : " << book1.title <<endl;
    //    cout << "第一本书作者 : " << book1.author <<endl;
    //    cout << "第一本书类目 : " << book1.subject <<endl;
    //    cout << "第一本书 ID : " << book1.book_id <<endl;
    printBook(book1);

    // 输出 book2 信息
    //    cout << "第二本书标题 : " << book2.title <<endl;
    //    cout << "第二本书作者 : " << book2.author <<endl;
    //    cout << "第二本书类目 : " << book2.subject <<endl;
    //    cout << "第二本书 ID : " << book2.book_id <<endl;
    printBook(book2);

    // 使用指针指向这两本书的对象
    Books* ptrBook1 = &book1;
    Books* ptrBook2 = &book2;

    // 输出书籍信息，传递指针
    printBookInfo(ptrBook1);
    printBookInfo(ptrBook2);


    return 0;
}